/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package com.xsm.gwt.widgets.client;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.dom.client.TableElement;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.dom.client.TableSectionElement;

/**
 * @author Sony Mathew
 */
public class FlexTable extends com.google.gwt.user.client.ui.FlexTable {
    
    private TableSectionElement thead = null;
    private TableRowElement headRow = null;
    
    public void createHeaderRow() {
        if (headRow != null) {
            return;//already exists.
        }
        thead = TableElement.as(this.getElement()).createTHead();
        headRow = thead.insertRow(-1);
    }

    /**
     * Append to the next cell.
     * 
     * author Sony Mathew
     */
    public void addHeaderText(String text) {
        setHeaderText(-1, text); //-1 means append.
    }

    /**
     * Append to the next cell.
     * 
     * author Sony Mathew
     */
    public void addHeaderHTML(String html) {
        setHeaderHTML(-1, html); //-1 means append.
    }
    
    /**
     * int col: the col to add it to. -1 means append.
     * 
     * author Sony Mathew
     */
    public void setHeaderText(int col, String text) {
        if (headRow == null) {
            createHeaderRow();
        }        
        TableCellElement th = Document.get().createTHElement();
        th.setInnerText(text);
        headRow.appendChild(th);        
    }

    /**
     * int col: the col to add it to. -1 means append.
     * 
     * author Sony Mathew
     */
    public void setHeaderHTML(int col, String html) {
        if (headRow == null) {
            createHeaderRow();
        }        
        TableCellElement th = Document.get().createTHElement();
        th.setInnerHTML(html);
        headRow.appendChild(th);        
    }
    
}
